<?php
	class GP_controleur
	{
		static $_instance;
		var $modele;
		
		// singleton
		public function &getInstance($nom, $modele = false) 
		{
			if (!self::$_instance instanceof self)
				self::$_instance = new self($nom, $modele);
			return self::$_instance;
		}
		
		function __construct($nom, $modele = false)
		{
			if ($modele)
				$this -> modele = 'modele/' . $nom . '.mod';
		}
		
		function add_html($page)
		{
			$html = new GP_template($page);
			
			if (!TPL_CACHE)
			{
				include($html -> page);
				@unlink($html -> page);
			}
			else
			{
				$id_tpl = md5($page . session_id() . APPLNG . REQUESTURI);
				$htmlpage = DIR_CACHE . $id_tpl . '.cache';
				if(is_file($htmlpage) && (time() - filemtime($htmlpage)) <= CACHE_DUREE)
					include($htmlpage);
				else
				{
					@unlink($htmlpage);
					@touch($htmlpage);
					ob_start();
					include($html -> page);
					$data = ob_get_contents();
					ob_end_flush();
					$fp = fopen($htmlpage, 'a');
					fwrite($fp, $data);
					fclose($fp);
				}
			}
		}
		
		function htmlrw($page)
		{
			global $gp_fonc;
			
			$html = new GP_template($page);
			$htmlpage = $gp_fonc -> html2($html -> page, 1);
			
			@unlink($html -> page);
			
			return $htmlpage;
		}
		
		function setvar($var, $val)
		{			
			$this -> $var = $val;
		}
	}
?>